home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!als-il2-02
- From: stefmit@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: [Q] Expression tree evaluation
- Date: 13 Apr 1996 22:07:38 GMT
- Organization: Netcom
- Message-ID: <4kp8ja$s6p@cloner2.ix.netcom.com>
- NNTP-Posting-Host: als-il2-02.ix.netcom.com
- X-NETCOM-Date: Sat Apr 13 3:07:38 PM PDT 1996
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- Could anybody tell me what's wrong with this (I am surely missing something):
-
- float ExprTree :: evaluate () const
- { if (root != 0)
- evaluateSub (root); }
-
- float ExprTree :: evaluateSub (ExprTreeNode *p) const
- { float result, l, r;
- if (isdigit (p -> element))
- result = ((p -> element) - '0');
- else { l = evaluateSub (p -> left);
- r = evaluateSub (p -> right); }
- switch (p -> element) {
- case '+' : result = l+r; break;
- case '-' : result = l-r; break;
- case '*' : result = l*r; break;
- case '/' : result = l/r; break;
- default : break;}
- return (result); }
-
- I am obviously trying to evaluate an expression, I "watched" l, r and result
- and they show correct values (while stepping through the program), but the
- program crashes with "stack underflow". Could anybody help, please? Thanks.
-